package lex.title.basic;

import java.awt.Frame;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/**
 * PropertyChangeListener installed on the Window. Updates the necessary state
 * as the state of the Window changes.
 */
class WindowStateChangeHandler implements PropertyChangeListener {
	private final BasicWindowTitle titlePane;

	WindowStateChangeHandler(BasicWindowTitle pane) {
		this.titlePane = pane;
	}

	public void propertyChange(PropertyChangeEvent e) {
		String name = e.getPropertyName();
		// Frame.state isn't currently bound.
		if ("resizable".equals(name) || "state".equals(name)) {
			Frame frame = this.titlePane.getFrame();
			if (frame != null) {
				this.titlePane.setState(frame.getExtendedState(), true);
			}
			if ("resizable".equals(name)) {
				this.titlePane.getRootPane().repaint();
			}
		} else if ("title".equals(name)) {
			this.titlePane.repaint();
		} else if ("componentOrientation".equals(name)) {
			this.titlePane.revalidate();
			this.titlePane.repaint();
		}
	}
}